﻿
Imports LibMultiPlug.Core.Plugins.Interfaces

Namespace Forms.Plugins

    Public Class PluginNavigationForm
        Inherits WeifenLuo.WinFormsUI.Docking.DockContent

        Private _imageList As ImageList

        Public Sub New()

            ' Dieser Aufruf ist für den Designer erforderlich.
            InitializeComponent()

            ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

            Call InternalInitialize()

        End Sub


        Private Sub InternalInitialize()

            _imageList = New ImageList
            _imageList.Images.Add("no_icon", My.Resources.plugin)

            Dim tn As TreeNode = tvPlugins.Nodes.Add("Plugins")

            For Each plugin As IPlugChildV1 In LibMultiPlug.Core.Plugins.PluginManager.GetInstance().Plugins
                FillNode(tn, plugin)
            Next

            tvPlugins.ImageList = _imageList

        End Sub

        Private Sub FillNode(ByVal parentNode As TreeNode, ByVal plugin As IPlugChildV1)

            Dim tn As TreeNode = parentNode.Nodes.Add(String.Format("{0}", plugin.Name))

            If plugin.Transaktion IsNot Nothing AndAlso plugin.Transaktion <> String.Empty Then
                tn.ToolTipText = "Transaktion: " & plugin.Transaktion
            End If

            If plugin.Icon Is Nothing Then
                tn.ImageKey = "no_icon"
                tn.SelectedImageKey = "no_icon"
            Else
                _imageList.Images.Add(plugin.Key, plugin.Icon)
                tn.ImageKey = plugin.Key
                tn.SelectedImageKey = plugin.Key
            End If

            tn.Name = plugin.Transaktion

            If plugin.Children IsNot Nothing AndAlso plugin.Children.Count > 0 Then
                For Each children As IPlugChildV1 In plugin.Children
                    FillNode(tn, children)
                Next
            End If

        End Sub

        Private Sub tvPlugins_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles tvPlugins.NodeMouseDoubleClick
            LibMultiPlug.Core.Plugins.PluginManager.GetInstance().StartTransaktion(e.Node.Name, Nothing)
        End Sub

    End Class

End Namespace